<template>
  <span>
<!--    <a-button type="primary" @click="showModal">
      Open Modal
    </a-button>-->

    <a @click="showModal" :disabled="finished" v-if="this.project.projectStatus != 'OVER'">项目结束</a>
    <a @click="showModal" v-if="this.project.projectStatus === 'OVER'">项目评分</a>
    <a-modal v-model="visible" title="项目完结" @ok="handleOk" width="1000px" okText="提交" >
      <a-form :form="form" >
        <a-form-item label="项目总结" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-model="comment.projectComment" rows="4" placeholder="请输入项目总结"/>
        </a-form-item>
        <a-form-item label="专家评分" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <dynamic-project-professor :professors="comment.professors" @updateProfessorData="updateProfessorData"/>
        </a-form-item>
        <a-form-item label="添加附件" :labelCol="labelCol" :wrapperCol="wrapperCol" >
          <j-upload v-model="fileList"></j-upload>
        </a-form-item>
      </a-form>
    </a-modal>
  </span>
</template>
<script>
  import JUpload from '@/components/jeecg/JUpload';
  import DynamicProjectProfessor from "./DynamicProjectProfessor";
  import {postAction} from '@/api/manage'
  export default {
    name: "ProjectProfessorComments",
    props:{
      project:{
        type:Object,
      }
    },
    data() {
      return {
        visible: false,
        form: this.$form.createForm(this),
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        comment:{
          projectComment:'',
          professors :[
            {
              key: '',
              name: '',
              type: '',
              value: 0,
            }],
        },
        url:{
          updateComment:'/projectProfessorInfo/updateComment',
        },
        finished:true,
        /*fileList是附件集合，保存URI*/
        fileList:[]
      };
    },
    components:{
      JUpload,
      DynamicProjectProfessor,
    },
    created() {
      // 把项目结束的附件回显到对应项目中
      this.fileList = this.project.projectOverFiles
      console.log(this.project.projectOwnProfessorList)
      // 获取参加项目的专家集合
      let professorList = this.project.projectOwnProfessorList
      // console.log("==========")
      // console.log(professorList)
      // 设置空集合
      let agreeProfessorList = []
      // 遍历专家集合
      for (let i=0;i<professorList.length;i++){
        // 如果专家同意参加
        if (professorList[i].states==1){
          // 放入空集合中
          agreeProfessorList.push(professorList[i])
        }
      }
      // 把同意的集合赋值给professors
      this.comment.professors = agreeProfessorList
      this.comment.projectComment = this.project.projectComment
      //
      // console.log("==========")
      // console.log(this.comment)
      // 如果项目结束了，才能使用评分
      if (this.project.projectStatus == 'FINISH' || this.project.projectStatus == 'OVER')
        this.finished = false
      else
        // 否则不能使用
        this.finished = true
      
    },
    methods: {
      showModal() {
        this.visible = true;
      },
      handleOk(e) {
        // console.log(this.professors);
        console.log('======')
        console.log(this.project.id)
        console.log('======')
        console.log(this.comment)
        console.log('======')
        let params={
          projectId:this.project.id,
          comment:this.comment.projectComment,
          professors:this.comment.professors,
          files:this.fileList
        }
        // axios发送到后端
        postAction(this.url.updateComment,params).then((res)=>{
            console.log(res.success)
          if (res.success == true){
            this.$message.success("评分成功！")
          }else {
            this.$message.error("评分失败！")
          }
            this.visible = false
        })
      },
      updateProfessorData(val){
          // 更新professorData
          // console.log(val)
        this.professors = val

      },
    },
  };
</script>
<style scoped>

</style>